//
//  CreditSectionViewController.m
//  PacIsBack
//
//  Created by Simon André on 08/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CreditSectionViewController.h"
#import "CreditElementViewContrller.h"
#import "Constants.h"


@implementation CreditSectionViewController

@synthesize sectionName, elements;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

-(id) initSectionWithName:(NSString*) name{
	if (self = [super init]) {
		NSMutableArray* elementsList = [[NSMutableArray alloc] init];
		if ([name compare:@"Développement"]==NSOrderedSame) {
			CreditElementViewContrller* elem = [[CreditElementViewContrller alloc] initWithName:@"SIMON André" andReference:@" "];
			[elementsList addObject:elem];
			[elem release];
			elem = [[CreditElementViewContrller alloc] initWithName:@"BRAULT Jérémy" andReference:@" "];
			[elementsList addObject:elem];
			[elem release];
		}
		if ([name compare:@"Artwork"]==NSOrderedSame) {
			CreditElementViewContrller* elem = [[CreditElementViewContrller alloc] initWithName:@"Sayu" andReference:@"Priscilla Grédé"];
			[elementsList addObject:elem];
			[elem release];
		}
		if ([name compare:@"Ressources Graphiques"]==NSOrderedSame) {
			CreditElementViewContrller* elem = [[CreditElementViewContrller alloc] initWithName:@"SIMON André" andReference:@" "];
			[elementsList addObject:elem];
			[elem release];
			elem = [[CreditElementViewContrller alloc] initWithName:@"Ragnarok Online" andReference:@"Gravity"];
			[elementsList addObject:elem];
			[elem release];
			elem = [[CreditElementViewContrller alloc] initWithName:@"Ragnarok Battle Offline" andReference:@"Soft Circle French-Bread"];
			[elementsList addObject:elem];
			[elem release];
			elem = [[CreditElementViewContrller alloc] initWithName:@"Ganbare Goemon 2" andReference:@"Konami"];
			[elementsList addObject:elem];
			[elem release];
		}
		if ([name compare:@"Musiques"]==NSOrderedSame) {
			CreditElementViewContrller* elem = [[CreditElementViewContrller alloc] initWithName:@"Ragnarok Battle Offline" andReference:@"Soft Circle French-Bread"];
			[elementsList addObject:elem];
			[elem release];
		}
		[self setElements:elementsList];
		[elementsList release];
		UIView* emptyView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, iphoneWidth, creditSectionTextSize+(textHeight*[[self elements] count]))];
		[self setView:emptyView];
		[emptyView release];
		UITextView* sectionTitleView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, iphoneWidth, creditSectionTextSize)];
		[sectionTitleView setEditable:NO];
		[sectionTitleView setScrollEnabled:NO];
		[sectionTitleView setText:name];
		[sectionTitleView setTextAlignment:UITextAlignmentCenter];
		[sectionTitleView setFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:15.0]];
		[[self view] addSubview:sectionTitleView];
		[sectionTitleView release];
		NSInteger creditZoneGap = creditSectionTextSize;
		for (CreditElementViewContrller* creditElem in [self elements]) {
			[[self view] addSubview:[creditElem view]];
			[[creditElem view] setCenter:CGPointMake(iphoneHalfWidth, creditZoneGap+[[creditElem view] frame].size.height/2)];
			creditZoneGap = creditZoneGap+textHeight;
		} 
		
	}
	return self;
}

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[self setElements:nil];
	[self setSectionName:nil];
	[super dealloc];
}


@end
